#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main(void)
{   
    int n=5;
    pid_t pid =-1;
	for(int i = 0; i < n; i++)
    {
        pid = fork();
        // printf("%d\n",i);
        if(pid < 0){
            perror("fork err");
            return -1;
        }else if(pid > 0)
        {   
            break;
        }
    }
    if(pid > 0){
        printf(" (PID:%d)\n",getpid());
        wait(NULL);
    }
    if(pid == 0){
        printf("in child (PID:%d), parent:%d\n",getpid(),getppid());
        exit(0);
    }


    
	return 0;
}
